package cn.yr.search.repository;

import cn.yr.search.bean.ArticleDocBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface ArticleElasticRepository extends ElasticsearchRepository<ArticleDocBean, Long> {

    @Query("{\"bool\" : {\"must\" : {\"field\" : {\"title\" : \"?\"}}}}")
    Page<ArticleDocBean> findByTitle(String content, Pageable pageable);

    @Query("{\"query\":{\"multi_match\":{\"query\":\"?\",\"fields\":[\"author\",\"title\",\"description\",\"contentFormat\"]}}}")
    Page<ArticleDocBean> find(String kw, Pageable pageable);

    @Query("{\"bool\" : {\"must\" : {\"field\" : {\"firstCode.keyword\" : \"?\"}}}}")
    Page<ArticleDocBean> findByFirstCode(String firstCode, Pageable pageable);

    @Query("{\"bool\" : {\"must\" : {\"field\" : {\"secordCode.keyword\" : \"?\"}}}}")
    Page<ArticleDocBean> findBySecordCode(String secordCode, Pageable pageable);

}
